package d0319;

import javax.sound.midi.Soundbank;

public class bank implements Runnable {
    private int money = 1000;
    Object obj = new Object();
    int i = 100;

    public void run() {
        while (true)
            synchronized (obj) {
                if (money > 0) {
                    System.out.println(Thread.currentThread().getName() + "取走" + i + "元,还剩" +(money-i)+ "元");
                    money -= 100;
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                } else {
                    break;
                }
            }
    }


    public static void main(String[] args) {
        bank admission = new bank();
        Thread t1 = new Thread(admission, "A");
        Thread t2 = new Thread(admission, "B");
        t1.start();
        t2.start();

    }
}
